Skip to content

fix(rpc): reject non-positive fund account amounts#1625

Open
vikions wants to merge 1 commit into
genlayerlabs:mainfrom
vikions:fix/reject-non-positive-fund-amount
Open

fix(rpc): reject non-positive fund account amounts#1625
vikions wants to merge 1 commit into
genlayerlabs:mainfrom
vikions:fix/reject-non-positive-fund-amount

Conversation

@vikions
Copy link
Copy Markdown

@vikions vikions commented May 10, 2026

Summary

Rejects non-positive sim_fundAccount amounts before creating or crediting a funding transaction.

Why

sim_fundAccount is expected to create funding transactions only for positive values. Accepting 0 can create useless transactions, while negative values can lead to invalid transfer semantics later in the simulator flow.

Changes

  • Validate amount > 0 in fund_account
  • Return JSON-RPC invalid params for non-positive amounts
  • Add focused tests for 0 and negative amounts
  • Assert invalid inputs do not instantiate the transaction processor or create crediting side effects

Test plan

  • python3 -m py_compile backend/protocol_rpc/endpoints.py tests/unit/test_simulator_sessions.py
  • git diff --check -- backend/protocol_rpc/endpoints.py tests/unit/test_simulator_sessions.py
  • python3 -m pytest tests/unit/test_simulator_sessions.py -q

Summary by CodeRabbit

Bug Fixes

  • The account funding endpoint now validates that the amount must be greater than 0, rejecting non-positive values with a clear error message (code -32602). Request validation checks now occur earlier in the process for improved efficiency.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 10, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bd834a80-29d5-4764-87eb-a2b3c2943e74

📥 Commits

Reviewing files that changed from the base of the PR and between 6736a15 and eb0ec6d.

📒 Files selected for processing (2)
  • backend/protocol_rpc/endpoints.py
  • tests/unit/test_simulator_sessions.py

📝 Walkthrough

Walkthrough

The pull request adds input validation to the fund_account RPC endpoint. The function now validates the account address and rejects non-positive amounts before creating a transaction processor, raising a standardized JSON-RPC error when validation fails. Unit tests verify both the rejection behavior and the existing successful transaction path.

Changes

fund_account Input Validation

Layer / File(s) Summary
Validation Logic
backend/protocol_rpc/endpoints.py
fund_account validates account_address before instantiation and rejects amount <= 0 with JSONRPCError (code -32602); TransactionsProcessor is created after validations pass.
Test Infrastructure & Validation Cases
tests/unit/test_simulator_sessions.py
Import JSONRPCError and add parametrized test ensuring fund_account rejects amounts 0 and -1, asserting correct error code, message, and no side effects.
Happy Path Verification
tests/unit/test_simulator_sessions.py
Extended existing test assertions to verify account manager's credit_tx_value_once is called with generated transaction hash, funded address, and amount.

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

A rabbit hops through validation gates,
Checking amounts before creating fates,
"No zeros or negatives!" the function declares,
With errors well-formed and tests that declare,
Transactions now guarded with mathematical care! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding validation to reject non-positive amounts in the fund_account function.
Description check ✅ Passed The description covers the what (changes), why (reasons), and testing done sections required by the template, with clear explanations and specific test execution details.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant